package fileio;

import java.io.File;
import java.io.FileFilter;

public class DeleteFiles {

	public static void main(String[] args) {

		File dir = new File("/home/network/Downloads");

		File[] oldFiles = dir.listFiles(new FileFilter() {
			long one_week = 604800000;
			long now = System.currentTimeMillis();

			@Override
			public boolean accept(File pathname) {
				if (pathname.isDirectory())
					return false;

				long lastModified = pathname.lastModified();
				long elapse = now - lastModified;
				System.out.println(elapse + " , " + pathname.getName());

				if (elapse >= one_week)
					return true;
				else
					return false;
			}
		});

		for (int i = 0; i < oldFiles.length; i++) {
			File file = oldFiles[i];
			System.out.println("old file = " + file);
		}

	}
}
